package com.ash.pool;

import org.apache.commons.dbcp2.BasicDataSource;

import java.io.FileReader;
import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.Properties;

/**
 * @encoding : UTF-8
 * @Time : 2020/12/8 15:03
 * @Author : Chen Chao
 * @File : connection.com.ash.pool.Test01.java
 * @Software : IntelliJ IDEA
 * @since : 1.8
 */
public class Test01 {
    public static void main(String[] args) {
        BasicDataSource basicDataSource = creatPool();
        try {
            Connection connection = basicDataSource.getConnection();
            connection.close();
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }

    public static BasicDataSource creatPool(){
        Properties properties = new Properties();
        try {
            properties.load(new FileReader("src/com/ash/util/connection.properties"));
        } catch (IOException e) {
            e.printStackTrace();
        }
        /*获取配置信息*/
        String className = properties.getProperty("className");
        String password = properties.getProperty("password");
        String user = properties.getProperty("user");
        String url = properties.getProperty("url");
        /*加载配置信息*/
        BasicDataSource ds = new BasicDataSource();
        ds.setDriverClassName(className);
        ds.setUsername(user);
        ds.setPassword(password);
        ds.setUrl(url);
        return ds;

    }
}
